package br.com.rookgraph;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.Reader;

public class LoadGraph {
	
	public static Graph file(String path){
		
		BufferedReader input = prepareInput(path);
		
		try {
			
			int size = Integer.parseInt(input.readLine());
			Graph graph = new Graph(size);
			
			String aresta;
			String[] vertices;
			do{
				aresta = input.readLine();
				if(aresta != null){
					vertices = aresta.split(" ");
					if (vertices != null) {
						graph.addEdge(Integer.valueOf(vertices[0]), Integer.valueOf(vertices[1]), 1);
					}
				}
			}while(aresta != null);
			
			return graph;
		}catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	
	}
	

	private static BufferedReader prepareInput(String args) {
		try {
			
			Reader inputStreamReader = args == null ? new InputStreamReader(System.in) : new FileReader(new File(args));
			
			BufferedReader input = new BufferedReader(inputStreamReader);
			
			return input;
			
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		}
		
		return null;
	}

}